package api

import (
	"gitee.com/h2ob/facada"
	h2of "gitee.com/h2ob/h2of/base"
	"github.com/gin-gonic/gin/binding"
)

type beginReq struct {
	ID string `json:"id"`
}

type dayContent struct {
	Day     string `json:"day"`
	Content string `json:"content"`
}

type TravelRsp struct {
	Link      string       `json:"link"`
	Itinerary []dayContent `json:"itinerary"`
}

type travelReq struct {
	Hash        string `json:"hash"`
	Destination string `json:"destination"`
	Duration    int    `json:"duration"`
	Budget      string `json:"budget"`
	Show        bool   `json:"showHiddenGems"`
	Activities  string `json:"activities"`
}

func beginItineraryGen() (string, error) {
	const url = "https://backend.planitearth.travel/beginItineraryGeneration"
	body, err := doGet(url, nil, nil)
	if err != nil {
		h2of.GLogger.Infof("call return:%s", err.Error())
		return "", err
	}
	req := beginReq{}
	err = binding.JSON.BindBody(body, &req)
	if err != nil {
		h2of.GLogger.Infof("parse:%s", err.Error())
		return "", err
	}
	h2of.GLogger.Infof("id:%s", req.ID)
	return req.ID, nil
}

func doGenItinerary(hash string, req *facada.H2oAiTravelReq) (*TravelRsp, error) {
	const url = "https://backend.planitearth.travel/generateItinerary"
	tReq := travelReq{Hash: hash, Destination: req.Destination, Duration: req.Duration,
		Budget: req.Budget, Show: req.Show, Activities: req.Activities}
	tRsp := &TravelRsp{}
	err := doPost(url, &tReq, tRsp)
	if err != nil {
		h2of.GLogger.Infof("call return:%s", err.Error())
		return nil, err
	}
	return tRsp, nil
}
